package convertor

import (
	"github.com/jinzhu/copier"
	"mine-info-server/domain/common-context/model/message-aggregate/aggregate"
	"mine-info-server/infra/database/mysql/common-context/message/po"
)

/*
   @author:zhongyang
   @date:2023/4/12
   @description:消息-DO和PO的转换器
*/

type Option func(aggregate *aggregate.MessageAggregate)

type MessageConvertor struct {
}

func (c *MessageConvertor) CreateAggregateByOption(opts ...Option) *aggregate.MessageAggregate {
	msg := &aggregate.MessageAggregate{}
	for _, opt := range opts {
		opt(msg)
	}
	return msg
}

func (c *MessageConvertor) ReadMsgPO(msg *aggregate.MessageAggregate) *po.RemindMsg {
	res := &po.RemindMsg{}
	_ = copier.Copy(&res, msg)
	return res
}

func WithRemindMsgPO(remindMsgPO *po.RemindMsg) Option {
	return func(aggregate *aggregate.MessageAggregate) {
		if remindMsgPO == nil {
			return
		}
		_ = copier.Copy(&aggregate, remindMsgPO)
	}
}
